<?php
return <<<EOT
CREATE TABLE IF NOT EXISTS `{tablePrefix}article` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(10) unsigned NOT NULL DEFAULT '0',
  `channel_id` int(10) unsigned NOT NULL DEFAULT '0',
  `title` varchar(255) NOT NULL,
  `content` text NOT NULL,
  `excerpt` varchar(255) NOT NULL DEFAULT '',
  `status` tinyint(4) NOT NULL DEFAULT '0',
  `sticky` int(11) NOT NULL DEFAULT '0',
  `promote` int(11) NOT NULL DEFAULT '0',
  `create_time` int(11) NOT NULL DEFAULT '0',
  `update_time` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `list` (`status`,`sticky`,`create_time`),
  KEY `frontpage` (`status`,`promote`,`sticky`,`create_time`),
  KEY `channel_id` (`channel_id`),
  KEY `update_time` (`update_time`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}article_meta`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}article_meta` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `object_id` int(11) unsigned NOT NULL,
  `meta_key` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `meta_value` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `post_meta` (`object_id`,`meta_key`),
  KEY `post_id` (`object_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}authassignment`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}authassignment` (
  `itemname` varchar(64) NOT NULL,
  `userid` varchar(64) NOT NULL,
  `bizrule` text,
  `data` text,
  PRIMARY KEY (`itemname`,`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}authitem`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}authitem` (
  `name` varchar(64) NOT NULL,
  `type` int(11) NOT NULL,
  `description` text,
  `bizrule` text,
  `data` text,
  PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}authitemchild`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}authitemchild` (
  `parent` varchar(64) NOT NULL,
  `child` varchar(64) NOT NULL,
  PRIMARY KEY (`parent`,`child`),
  KEY `child` (`child`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}banner`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}banner` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `category_id` int(10) unsigned NOT NULL,
  `name` varchar(255) NOT NULL,
  `description` varchar(255) NOT NULL DEFAULT '',
  `link_href` varchar(255) NOT NULL,
  `link_target` varchar(16) NOT NULL,
  `visible` tinyint(3) unsigned NOT NULL DEFAULT '1',
  `weight` int(11) NOT NULL DEFAULT '0',
  `create_time` int(11) NOT NULL DEFAULT '0',
  `update_time` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `list` (`weight`,`name`),
  KEY `category` (`category_id`),
  KEY `visible` (`visible`),
  KEY `update_time` (`update_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}channel`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}channel` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL COMMENT '标题',
  `en_title` varchar(255) NOT NULL DEFAULT '' COMMENT '英文标题',
  `name` varchar(255) NOT NULL COMMENT '名称',
  `path` varchar(255) NOT NULL COMMENT '路径',
  `bundle` varchar(64) NOT NULL DEFAULT '' COMMENT '栏目捆绑的模型类',
  `parent_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父级ID',
  `keywords` varchar(255) NOT NULL COMMENT '关键字',
  `description` text NOT NULL COMMENT '描述',
  `type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '类型',
  `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
  `weight` int(11) NOT NULL DEFAULT '0' COMMENT '权重',
  `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态',
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`),
  UNIQUE KEY `path` (`path`),
  KEY `status` (`status`),
  KEY `list` (`weight`,`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}file`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}file` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `meta` text,
  `user_id` int(10) unsigned NOT NULL DEFAULT '0',
  `bundle` varchar(32) NOT NULL,
  `filename` varchar(255) NOT NULL DEFAULT '',
  `uri` varchar(255) NOT NULL DEFAULT '',
  `filemime` varchar(255) NOT NULL DEFAULT '',
  `filesize` int(10) unsigned NOT NULL DEFAULT '0',
  `status` tinyint(4) NOT NULL DEFAULT '0',
  `create_time` int(10) unsigned NOT NULL DEFAULT '0',
  `update_time` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  KEY `status` (`status`),
  KEY `bundle` (`bundle`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}file_usage`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}file_usage` (
  `file_id` int(10) unsigned NOT NULL,
  `object_id` int(10) unsigned NOT NULL,
  `bundle` varchar(32) NOT NULL DEFAULT '',
  `field` varchar(32) NOT NULL DEFAULT '',
  `weight` int(11) NOT NULL DEFAULT '0',
  `download_count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`file_id`),
  KEY `file_list` (`object_id`,`bundle`(16),`field`,`weight`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}link`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}link` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category_id` int(10) unsigned NOT NULL DEFAULT '0',
  `name` varchar(255) NOT NULL,
  `description` varchar(255) NOT NULL,
  `link_href` varchar(255) NOT NULL,
  `link_target` varchar(16) NOT NULL,
  `visible` tinyint(3) unsigned NOT NULL DEFAULT '1',
  `weight` int(11) NOT NULL DEFAULT '0',
  `create_time` int(11) NOT NULL DEFAULT '0',
  `update_time` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `visible` (`visible`),
  KEY `category_id` (`category_id`),
  KEY `list` (`weight`,`name`),
  KEY `update_time` (`update_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}node`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}node` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(10) unsigned NOT NULL DEFAULT '0',
  `channel_id` int(10) unsigned NOT NULL DEFAULT '0',
  `title` varchar(255) NOT NULL,
  `excerpt` text NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT '0',
  `sticky` int(11) NOT NULL DEFAULT '0',
  `promote` int(11) NOT NULL DEFAULT '0',
  `create_time` int(11) NOT NULL DEFAULT '0',
  `update_time` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `update_time` (`update_time`),
  KEY `user_id` (`user_id`),
  KEY `frontpage` (`channel_id`,`status`,`promote`,`sticky`,`create_time`),
  KEY `list` (`channel_id`,`status`,`sticky`,`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}option`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}option` (
  `name` varchar(128) NOT NULL DEFAULT '',
  `value` longblob NOT NULL,
  PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}page`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}page` (
  `channel_id` int(10) unsigned NOT NULL,
  `content` longtext NOT NULL,
  PRIMARY KEY (`channel_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}role`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}role` (
  `name` varchar(64) NOT NULL,
  `description` varchar(255) NOT NULL,
  `weight` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`name`),
  KEY `list` (`weight`,`description`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}taxonomy`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}taxonomy` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `description` text COLLATE utf8_unicode_ci NOT NULL,
  `hierarchy` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `weight` int(11) NOT NULL DEFAULT '0',
  `bundle` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  KEY `name` (`slug`),
  KEY `list` (`weight`,`name`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}term`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}term` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `taxonomy_id` int(11) NOT NULL DEFAULT '0',
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `description` text COLLATE utf8_unicode_ci NOT NULL,
  `weight` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `taxonomy_tree` (`taxonomy_id`,`weight`,`name`),
  KEY `slug_taxonomy` (`slug`,`taxonomy_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}term_hierarchy`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}term_hierarchy` (
  `term_id` int(10) unsigned NOT NULL DEFAULT '0',
  `parent_id` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`term_id`,`parent_id`),
  KEY `parent` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}term_meta`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}term_meta` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `object_id` int(11) unsigned NOT NULL,
  `meta_key` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `meta_value` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `post_meta` (`object_id`,`meta_key`),
  KEY `post_id` (`object_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}term_object`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}term_object` (
  `bundle` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `object_id` int(10) unsigned NOT NULL,
  `term_id` int(10) unsigned NOT NULL,
  `create_time` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`bundle`(16),`object_id`,`term_id`),
  KEY `term_object` (`bundle`(16),`term_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}user`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}user` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(64) NOT NULL,
  `nickname` varchar(64) NOT NULL,
  `email` varchar(128) NOT NULL,
  `password_hash` varchar(64) NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT '0',
  `token` varchar(64) DEFAULT NULL,
  `create_time` int(11) NOT NULL DEFAULT '0',
  `update_time` int(11) NOT NULL DEFAULT '0',
  `login_time` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`,`email`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `{tablePrefix}watchdog`
--

CREATE TABLE IF NOT EXISTS `{tablePrefix}watchdog` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '事件记录ID',
  `user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '事件记录的用户ID',
  `type` varchar(64) NOT NULL COMMENT '事件类型',
  `message` longtext NOT NULL COMMENT '事件消息',
  `variables` longblob NOT NULL COMMENT '事件参数',
  `location` text NOT NULL COMMENT '事件发生的URL',
  `referer` text COMMENT '事件url来源',
  `hostname` varchar(128) NOT NULL COMMENT '发生事件的主机地址',
  `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '发生时间',
  PRIMARY KEY (`id`),
  KEY `type` (`type`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- 限制导出的表
--

--
-- 限制表 `{tablePrefix}authassignment`
--
ALTER TABLE `{tablePrefix}authassignment`
  ADD CONSTRAINT `{tablePrefix}authassignment_ibfk_1` FOREIGN KEY (`itemname`) REFERENCES `{tablePrefix}authitem` (`name`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- 限制表 `{tablePrefix}authitemchild`
--
ALTER TABLE `{tablePrefix}authitemchild`
  ADD CONSTRAINT `{tablePrefix}authitemchild_ibfk_1` FOREIGN KEY (`parent`) REFERENCES `{tablePrefix}authitem` (`name`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `{tablePrefix}authitemchild_ibfk_2` FOREIGN KEY (`child`) REFERENCES `{tablePrefix}authitem` (`name`) ON DELETE CASCADE ON UPDATE CASCADE;

EOT;
